
package sample.tomcat;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.core.SpringVersion;

/**
 *
 * 这个是源码启动类入口
 *SpringBootApplication注解是springboot的核心注解，用户开启自动配置（准确的说是通过内组合注解EnableAutoConfiguration）
 *
 * SpringBootApplication注解中组合了@SpringBootConfiguration、@EnableAutoConfiguration和@ComponentScan，因此也可以使用这三个注解代替@SpringBootApplication注解
 * */

@SpringBootApplication
public class SampleTomcatApplication {

	private static Log logger = LogFactory.getLog(SampleTomcatApplication.class);

	@Bean
	protected ServletContextListener listener() {
		return new ServletContextListener() {

			@Override
			public void contextInitialized(ServletContextEvent sce) {
				logger.info("ServletContext initialized");
			}

			@Override
			public void contextDestroyed(ServletContextEvent sce) {
				logger.info("ServletContext destroyed");
			}

		};
	}
	//启动方式一
	public static void main(String[] args) {
		SpringApplication.run(SampleTomcatApplication.class, args);
	}
	//启动方式二
	public static void main2(String... args){
		new SpringApplicationBuilder(SampleTomcatApplication.class)
				.main(SpringVersion.class)
				.run(args);
	}


}
